var app = getApp()
let animationShowHeight = 300;
Page({
  data: {
    animationData: "",//排序弹出框动画
    animationData2: "",//筛选弹出框动画
    showModalStatus: false,//排序弹出框显示状态
    showModalStatus: false,//筛选弹出框显示状态
    sortIndex:0,//排序索引
    itemIndex:0,//顶部选择条件项索引
    screenIndex:-1,//筛选索引
    templateList:[1,2,3,4,5,6,7]
  },
  onLoad: function (e) {
    var that = this
    //获取屏幕高度，设置scrollview高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windHeight: res.windowHeight - 50 + "px"
        })

      }
    });
   
  },
  onReady: function () {

  },

  onShow: function (options) {
    
  },
  //绑定排序
  bindSortItem: function (e) {
    var index = e.currentTarget.dataset.index
    this.setData({
      sortIndex:index,
      itemIndex:0,
      screenIndex:-1,
      showModalStatus2: false,
    })
  },
  //绑定销量
  bindSales:function(e){
    this.setData({
      itemIndex:1,
      sortIndex:-1,
      showModalStatus:false,
      showModalStatus2: false,
      screenIndex: -1,
    })
  },
  //绑定筛选
  bindScreenItem:function(e){
    var index = e.currentTarget.dataset.index
    this.setData({
      screenIndex: index,
      itemIndex: 2,
      showModalStatus: false,
      sortIndex: -1,
    })
  },
  showModal: function (e) {    
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(0).step()
    this.setData({
      animationData: animation.export(),
      showModalStatus: true,
      showModalStatus2:false
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export()
      })
    }.bind(this), 200)

    
  },
  hideModal: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation;
    animation.translateY(animationShowHeight).step()
    this.setData({
      animationData: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData: animation.export(),
        showModalStatus: false
      })
    }.bind(this), 200)
  },

  showModal2: function (e) {
    // 显示遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation
    animation.translateY(0).step()
    this.setData({
      animationData2: animation.export(),
      showModalStatus2: true,
      showModalStatus:false
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData2: animation.export()
      })
    }.bind(this), 200)


  },
  hideModal2: function () {
    // 隐藏遮罩层
    var animation = wx.createAnimation({
      duration: 200,
      timingFunction: "linear",
      delay: 0
    })
    this.animation = animation;
    animation.translateY(animationShowHeight).step()
    this.setData({
      animationData2: animation.export(),
    })
    setTimeout(function () {
      animation.translateY(0).step()
      this.setData({
        animationData2: animation.export(),
        showModalStatus2: false
      })
    }.bind(this), 200)
  },
  //跳转到模板详情
  navigateTo:function(){
    wx.navigateTo({
      url: '/pages/template/market/market-detail',
    })
  }
 
}) 
